package tool.plot

import java.io.File

import implicits.Implicits._
import shared.Pojo._
import tool.Pojo._
import tool.Tool
import tool.plot.AllPlot.RPlotB


/**
 * Created by yz on 27/9/2020
 */
object Lda extends LdaT with RPlotB {

  def producePlotConfigFile(data: AllPlotData, workspaceDir: File, extraData: ExtraDataData) = {
    Tool.dataCoverConfigFile(data, workspaceDir, configFileName, configJsonFileName)
  }

  override def getCommand(data: AllPlotData, extraData: ExtraDataData): String = {
    val lsrs = if (data.layout.resorientation == "v") " --left_space 0.02 --right_space 0.98" else ""
    val title = if (data.mainTitle.nonBlank) s" --title ${data.mainTitle}" else ""
    s"""
       |python ${new File(Tool.pyPath, "plot_res.py").unixPath}  lefse_LDA.xls lefse_LDA.pdf --dpi 300 ${title} --format pdf --width ${data.layout.width} --feature_font_size ${data.xFont} --title_font_size ${data.mainTitleFont} --height ${data.layout.height} --orientation ${data.layout.resorientation} ${lsrs} --subclades ${data.layout.resnscl} --class_legend_font_size ${data.legendFont} --max_feature_len ${data.layout.resmfl}
       |convert  -density 300 lefse_LDA.pdf  lefse_LDA.png
       |""".stripMargin
  }

  override def defaultPlotArg(tmpPlotData: AllPlotData): AllPlotData = {
    val initData = AllPlotData()
    tmpPlotData.copy(
      layout = tmpPlotData.layout.copy(
        width = "10",
        height = "4",
        resorientation = initData.layout.resorientation,
        resnscl = initData.layout.resnscl,
        resmfl = initData.layout.resmfl,
      ),
    )
  }

}

